package com.zmx.doctor.view.activity;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import androidx.core.app.ActivityCompat;

import com.zmx.doctor.BaseActivity;
import com.zmx.doctor.R;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LiveSetActivity extends BaseActivity {

    @BindView(R.id.button1)
    Button button1;
    @BindView(R.id.button2)
    Button button2;
    @BindView(R.id.layout0)
    RelativeLayout layout0;
    @BindView(R.id.layout)
    RelativeLayout layout;
    @BindView(R.id.layout1)
    RelativeLayout layout1;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_live_set;
    }

    @Override
    protected void initViews() {

        setToolbar(R.id.tool_bar);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    //需要的权限数组 读/写/相机
    private static String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};

    @OnClick({R.id.button1, R.id.button2,R.id.layout0, R.id.layout, R.id.layout1})
    public void onViewClicked(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.button1:

                intent.setClass(mActivity, SubscribeActivity.class);
                startActivity(intent);

                break;
            case R.id.button2:

                //检查是否已经获得相机的权限
                if (verifyPermissions(this, PERMISSIONS_STORAGE[2]) == 0) {
                    ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, 3);
                } else {
                    //已经有权限
                    toCamera();  //打开相机
                }
                break;

            case R.id.layout0:
                intent.setClass(mActivity, LiveDetailsActivity.class);
                startActivity(intent);
                break;
            case R.id.layout:
                intent.setClass(mActivity, LiveDetailsActivity.class);
                startActivity(intent);
                break;
            case R.id.layout1:
                intent.setClass(mActivity, LiveDetailsActivity.class);
                startActivity(intent);
                break;
        }
    }

    //跳转相机
    private void toCamera() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  //跳转到 ACTION_IMAGE_CAPTURE
        //判断内存卡是否可用，可用的话就进行存储
        //putExtra：取值，Uri.fromFile：传一个拍照所得到的文件，fileImg.jpg：文件名
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "fileImg.jpg")));
        startActivityForResult(intent, 101); // 101: 相机的返回码参数（随便一个值就行，只要不冲突就好）

    }


}
